import java.util.*;

public class db_table {
	public String sName;
	public long lGroup;
	public long lDataGroup;
	public long lIndexGroup;
	public int iRowSize;
	public ArrayList<db_index> oIndex = new ArrayList<db_index>();
	public ArrayList<db_column> oColumns = new ArrayList<db_column>();
	
	db_table(String sTableName, long lGroupVal, long lDataGroupVal, long lIndexGroupVal, ArrayList<db_index> oIndexVal, ArrayList<db_column> oCols){
		sName = sTableName;
		lGroup = lGroupVal;
		lDataGroup = lDataGroupVal;
		lIndexGroup = lIndexGroupVal;
		oIndex = oIndexVal;
		oColumns = oCols;
		iRowSize = 4; // Row status code
		for (int i = 0; i < oColumns.size(); i++) {
			iRowSize += oColumns.get(i).lLength;
			if (oColumns.get(i).lType == db_util.DB_DATATYPE_VARCHAR)
				iRowSize += 4;
		}			
		
	}


	public int iColumnPosition(String sColumnName) {
		sColumnName = sColumnName.toLowerCase();
		int iPos = 4; // Row status code
		for (int i = 0; i < oColumns.size(); i++) {
			if (sColumnName.equals(oColumns.get(i).sName.toLowerCase()))
					break;
			iPos += oColumns.get(i).lLength;
			if (oColumns.get(i).lType == db_util.DB_DATATYPE_VARCHAR)
				iPos += 4;
		}		
		return iPos;
	}
	public db_column oGetColumn(String sColumnName) {
		sColumnName = sColumnName.toLowerCase();
		for (int i = 0; i < oColumns.size(); i++) {
			if (sColumnName.equals(oColumns.get(i).sName.toLowerCase()))
				return oColumns.get(i);
		}
		return null;
	}
}
